export default class RouteStack {
    private stack:cc.Node[] = []

    public push(page:cc.Node):void {
        let index = this.stack.findIndex(v=> v.name === page.name)
        if(index>-1) {
            //页面已经在栈中存在，移动到栈顶
            this.stack.splice(index,1)
            this.stack.push(page)
        }else {
            this.stack.push(page)
        }
        console.log(this.stack)
        if(this.stack.length>1) {
            console.log(111)
            this.stack[this.stack.length-2].zIndex = this.stack.length
        }
    }

    public pop():cc.Node {
        return this.stack.pop()
    }

    public clear():void {
        this.stack = []
    }

    public length():number {
        return this.stack.length
    }
}